<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./node_modules/vue/dist/vue.js"></script>
</head>

<body>
    <div id="app">
        添加一个课程：<input type="text" v-model="text"> 
        <button @click="addItem">添加</button>
        <ul>
           <li v-for="(item,index) in course" :key="item.id"><input type="checkbox">  标题：{{item.title}}</li>
        </ul>
    </div>
    <script>
        new Vue({
            el: "#app",
            data: {
               text:"",
               id:4,
               //课程
               course: [
                    {
                        id: 1,
                        title: "暑假班"
                    },
                    {
                        id: 2,
                        title: "英语特长班"
                    },
                    {
                        id: 3,
                        title: "疯狂屋里"
                    },
                    {
                        id: 4,
                        title: "疯狂化学"
                    }
                ]
            },
            methods: {
                addItem(){
                    this.id++ ; //id递增
                    this.course.unshift({
                        id:this.id,
                        title:this.text
                    });
                    console.log(this.course);
                }
            }
        })
    </script>
</body>

</html>